package com.education.wisdom.controller;


import com.education.common.utils.ApiReturnObject;
import com.education.wisdom.pojo.CurrencyRecord;
import com.education.wisdom.service.ICurrencyRecordService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
import java.util.List;

@RestController
@RequestMapping("/web/currencyRecord")
public class FullCurrencyRecordController {

    @Autowired
    private ICurrencyRecordService currencyRecordService;

    /**
     * 达人币支付记录
     *
     * @return
     */
    @GetMapping("/Payment")
    public ApiReturnObject details(CurrencyRecord currencyRecord, Integer pageNum, Integer pageSize) {
        if (pageNum != null && pageSize != null) {
            PageHelper.startPage(pageNum, pageSize);
        }
        List<CurrencyRecord> currencyRecordList = currencyRecordService.selectCurrencyRecordList(currencyRecord);
        PageInfo<CurrencyRecord> pageInfo = new PageInfo<>(currencyRecordList);
        return new ApiReturnObject("200", "success", pageInfo);
    }

    /**
     * 详情查询
     */
    @GetMapping("/selectOne")
    public ApiReturnObject selectOne(Integer id) {
        CurrencyRecord currencyRecord = currencyRecordService.selectCurrencyRecordById(id);
        BigDecimal currency = currencyRecord.getCurrency();
        if (currency.compareTo(BigDecimal.ZERO) == (-1)) {
            currencyRecord.setCurrency(currency.multiply(new BigDecimal(-1)));
        }
        return new ApiReturnObject("200", "查询成功", currencyRecord);
    }


}
